package com.cloud.code.牛客网;

import java.util.Scanner;

/**
 * HJ33 整数与IP地址间的转换
 */
public class Test10 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String ip = scanner.nextLine();
            Long num = scanner.nextLong();

            ipToNum(ip);
            numToIp(num);
        }

    }

    private static void numToIp(Long num) {
        String binaryString = Long.toBinaryString(num);

        for (int i = 0; binaryString.length() < 32; i++) {
            binaryString = "0"+binaryString;
        }
        StringBuffer stringBuffer = new StringBuffer();
        int count = 0;
        for (int i = 0; i < 4; i++) {
            String substring = binaryString.substring(count, count + 8);
            Integer integer = Integer.valueOf(substring, 2);
            if(i==3){
                stringBuffer.append(integer);
            }else {
                stringBuffer.append(integer).append(".");
            }
            count = count+8;
        }
        System.out.println(stringBuffer);
    }

    private static void ipToNum(String ip) {
        String[] split = ip.split("\\.");
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < split.length; i++) {
            String binaryString = Integer.toBinaryString(Integer.parseInt(split[i]));
            if(binaryString.length()<8){
                for (int j = 0; j < 8 - binaryString.length(); j++) {
                    stringBuffer.append("0");
                }
            }
            stringBuffer.append(binaryString);
        }

        System.out.println(Long.valueOf(stringBuffer.toString(),2));
    }

}
